﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace TestRecordDisting
{
    public partial class Form1 : Form
    {
        YZH.Audio.Disting.RecorderDisting _driver = new YZH.Audio.Disting.RecorderDisting();
        public Form1()
        {
            InitializeComponent();
            _driver.OnMessage = new YZH.Audio.Disting.RecorderDisting.OnMessageHandler((obj, msg,isStop) => {
                string myMsg = "";
                if(isStop)
                {
                    myMsg = string.Format("{0},停止服务!\r\n",msg);
                }
                else
                {
                    myMsg = msg + "\r\n";
                }
                Invoke(new MethodInvoker(() => {
                    textBox1.Text += myMsg;
                }));
            });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _driver.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _driver.Stop();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            _driver.Dispose();
        }

        private string wakeupword = "(盾构|专家)*";
        private void button3_Click(object sender, EventArgs e)
        {
            bool has = true;
            var hearWord = "你好。";
            var wakeups = "盾构|专家|你好".Split('|');
            foreach (var wakeup in wakeups)
            {
                has = true;
                if (string.IsNullOrEmpty(wakeup)) continue;

                foreach (var word in wakeup)
                {
                    if (!hearWord.Contains(word))
                    {
                        has = false;
                        break;
                    }
                }
                if (has) break;
            }

        }
    }
}
